package com.letfox.test.example;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.collections.map.HashedMap;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import com.letfox.statistical.dao.DeviceStatisticDao;
import com.letfox.statistical.enums.UDMDelEnums;
import com.letfox.statistical.model.UDMDeviceStatistic;
import com.letfox.test.util.DateUtil;
import com.letfox.test.util.MyBatisUtil;


 
/**
 * 单元测试
 */
public class DeviceStatisticExample {

	/**
	 * 需要单元测试的时候在取消注释
	 */
	private DeviceStatisticDao deviceStatisticDao;
	@Test
	public void DeviceStatistic_add_Test(){
		
		try {
			SqlSession session = MyBatisUtil.getSqlSession(true);
			UDMDeviceStatistic DeviceStatistic = new UDMDeviceStatistic();
			DeviceStatistic.setUdmAdDeviceId("0011");
			DeviceStatistic.setAdPlanId("001");
			DeviceStatistic.setDevice("abc");
			DeviceStatistic.setPlayTime(new Date());
			DeviceStatistic.setShowTimes(1);
			DeviceStatistic.setClickTimes(1);
			DeviceStatistic.setDownloadTimes(1);
			DeviceStatistic.setAmount(new BigDecimal("10000.54"));
			DeviceStatistic.setCreateTime(new Date());
			DeviceStatistic.setUpdateTime(new Date());
			DeviceStatistic.setCreateBy("admin");
			DeviceStatistic.setUpdateBy("user");
			DeviceStatistic.setDel(UDMDelEnums.UDMDel.EFFECTIVE.getValue());
			
			deviceStatisticDao = session.getMapper(DeviceStatisticDao.class);
			deviceStatisticDao.insert(DeviceStatistic);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Test
	public void DeviceStatistic_update_Test(){
		
		try {
			SqlSession session = MyBatisUtil.getSqlSession(true);

			UDMDeviceStatistic DeviceStatistic = new UDMDeviceStatistic();
			DeviceStatistic.setUdmAdDeviceId("0011");
			DeviceStatistic.setAdPlanId("001");
			DeviceStatistic.setDevice("abc");
			DeviceStatistic.setPlayTime(new Date());
			DeviceStatistic.setShowTimes(1);
			DeviceStatistic.setClickTimes(1);
			DeviceStatistic.setDownloadTimes(1);
			DeviceStatistic.setAmount(new BigDecimal("10000.54"));
			DeviceStatistic.setCreateTime(new Date());
			DeviceStatistic.setUpdateTime(new Date());
			DeviceStatistic.setCreateBy("admin");
			
			DeviceStatistic.setUpdateBy("user");
			DeviceStatistic.setDel(UDMDelEnums.UDMDel.DELETE.getValue());
			
			deviceStatisticDao = session.getMapper(DeviceStatisticDao.class);
			int i = deviceStatisticDao.update(DeviceStatistic);
			System.out.println(i+"-----------------------------------");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	
	@Test
	public void DeviceStatistic_select_Test(){
		
		try {
			SqlSession session = MyBatisUtil.getSqlSession(true);
			UDMDeviceStatistic DeviceStatistic = new UDMDeviceStatistic();
			
			Map map = new HashedMap();

			map.put("adPutintoId", "001");
			map.put("device", "abc");
			map.put("startTime", DateUtil.strToDateSql("2018-03-17 18:00:00"));
			map.put("endTime", DateUtil.strToDateSql("2018-03-18 18:00:00"));
			
			
			deviceStatisticDao = session.getMapper(DeviceStatisticDao.class);
			List<UDMDeviceStatistic>  DeviceStatistics= deviceStatisticDao. getList(map);
			System.out.println(DeviceStatistics.size()+"-----------------------------------");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
}
